let express = require("express")();
let expressStatic = require("express-static");
const port = 81;

let mysql = require('mysql');

// 规划一个数据库链接
let sql = mysql.createConnection({
  host     : 'localhost',
  user     : 'root',
  password : '123456',
  database : 'chuan',
  timezone : "08:00"
});

// 尝试链接
sql.connect();


express.get("/getnewsList",(request,response)=>{
	sql.query(`SELECT * FROM shuju`,(error,data)=>{
		response.send(data)
	})
})

express.get("/getnews",(request,response)=>{
    let id = request.query.id;
    sql.query(`SELECT * FROM shuju WHERE id = ${id}`,(error,data)=>{
        response.send(data[0])
    })
})

express.use(expressStatic(__dirname + '/chuanyue1'));
console.log(`running at ${port}`);
express.listen(port)